package Form;

import javax.swing.JPanel;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import java.awt.GridBagConstraints;
import java.awt.Font;
import java.awt.Insets;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

import Control.CommonControls;
import Control.Job_Update_Controller;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Job_UpdateForm extends JPanel{
	private JLabel lblNewLabel;
	private JLabel lblNewLabel_3;
	private JTextField JobName;
	private JLabel lblNewDescription;
	private JTextField JobDesc;
	private JLabel lblNewSalary;
	private JLabel lblNewAmountOf;
	private JLabel lblJobIdto;
	private JTextField jobID;
	private JButton btnUpdate;
	
	Job_Update_Controller Controller;
	private JFrame parser; 
	private JSpinner salarySpinner;
	private JSpinner noSlots;
	
	public JFrame getParser() {
		return parser;
	}

	public void setParser(JFrame parser) {
		this.parser = parser;
	}

	public Job_UpdateForm(JFrame parser) { 
		setParser(parser);
		Controller = new Job_Update_Controller(this);
		
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 150, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
		gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel.gridx = 2;
		gbc_lblNewLabel.gridy = 0;
		add(getLblNewLabel(), gbc_lblNewLabel);
		GridBagConstraints gbc_lblJobIdto = new GridBagConstraints();
		gbc_lblJobIdto.anchor = GridBagConstraints.EAST;
		gbc_lblJobIdto.insets = new Insets(0, 0, 5, 5);
		gbc_lblJobIdto.gridx = 1;
		gbc_lblJobIdto.gridy = 2;
		add(getLblJobIdto(), gbc_lblJobIdto);
		GridBagConstraints gbc_jobID = new GridBagConstraints();
		gbc_jobID.anchor = GridBagConstraints.WEST;
		gbc_jobID.insets = new Insets(0, 0, 5, 5);
		gbc_jobID.gridx = 2;
		gbc_jobID.gridy = 2;
		add(getJobID(), gbc_jobID);
		GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
		gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewLabel_3.gridx = 1;
		gbc_lblNewLabel_3.gridy = 5;
		add(getLblNewLabel_3(), gbc_lblNewLabel_3);
		GridBagConstraints gbc_JobName = new GridBagConstraints();
		gbc_JobName.anchor = GridBagConstraints.WEST;
		gbc_JobName.insets = new Insets(0, 0, 5, 5);
		gbc_JobName.gridx = 2;
		gbc_JobName.gridy = 5;
		add(getJobName(), gbc_JobName);
		GridBagConstraints gbc_lblNewDescription = new GridBagConstraints();
		gbc_lblNewDescription.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewDescription.gridx = 1;
		gbc_lblNewDescription.gridy = 7;
		add(getLblNewDescription(), gbc_lblNewDescription);
		GridBagConstraints gbc_JobDesc = new GridBagConstraints();
		gbc_JobDesc.anchor = GridBagConstraints.WEST;
		gbc_JobDesc.insets = new Insets(0, 0, 5, 5);
		gbc_JobDesc.gridx = 2;
		gbc_JobDesc.gridy = 7;
		add(getJobDesc(), gbc_JobDesc);
		GridBagConstraints gbc_lblNewSalary = new GridBagConstraints();
		gbc_lblNewSalary.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewSalary.gridx = 1;
		gbc_lblNewSalary.gridy = 9;
		add(getLblNewSalary(), gbc_lblNewSalary);
		GridBagConstraints gbc_salarySpinner = new GridBagConstraints();
		gbc_salarySpinner.anchor = GridBagConstraints.WEST;
		gbc_salarySpinner.insets = new Insets(0, 0, 5, 5);
		gbc_salarySpinner.gridx = 2;
		gbc_salarySpinner.gridy = 9;
		add(getSalarySpinner(), gbc_salarySpinner);
		GridBagConstraints gbc_lblNewAmountOf = new GridBagConstraints();
		gbc_lblNewAmountOf.insets = new Insets(0, 0, 5, 5);
		gbc_lblNewAmountOf.anchor = GridBagConstraints.EAST;
		gbc_lblNewAmountOf.gridx = 1;
		gbc_lblNewAmountOf.gridy = 11;
		add(getLblNewAmountOf(), gbc_lblNewAmountOf);
		GridBagConstraints gbc_noSlots = new GridBagConstraints();
		gbc_noSlots.anchor = GridBagConstraints.WEST;
		gbc_noSlots.insets = new Insets(0, 0, 5, 5);
		gbc_noSlots.gridx = 2;
		gbc_noSlots.gridy = 11;
		add(getNoSlots(), gbc_noSlots);
		GridBagConstraints gbc_btnUpdate = new GridBagConstraints();
		gbc_btnUpdate.insets = new Insets(0, 0, 0, 5);
		gbc_btnUpdate.gridx = 2;
		gbc_btnUpdate.gridy = 13;
		add(getBtnUpdate(), gbc_btnUpdate);
	}

	public JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("Update Job");
			lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 20));
		}
		return lblNewLabel;
	}
	public JLabel getLblNewLabel_3() {
		if (lblNewLabel_3 == null) {
			lblNewLabel_3 = new JLabel("New Name:");
			lblNewLabel_3.setFont(new Font("Tahoma", Font.PLAIN, 15));
		}
		return lblNewLabel_3;
	}
	public JTextField getJobName() {
		if (JobName == null) {
			JobName = new JTextField();
			JobName.setColumns(10);
		}
		return JobName;
	}
	public JLabel getLblNewDescription() {
		if (lblNewDescription == null) {
			lblNewDescription = new JLabel("New Description:");
			lblNewDescription.setFont(new Font("Tahoma", Font.PLAIN, 15));
		}
		return lblNewDescription;
	}
	public JTextField getJobDesc() {
		if (JobDesc == null) {
			JobDesc = new JTextField();
			JobDesc.setColumns(10);
		}
		return JobDesc;
	}
	public JLabel getLblNewSalary() {
		if (lblNewSalary == null) {
			lblNewSalary = new JLabel("New Salary:");
			lblNewSalary.setFont(new Font("Tahoma", Font.PLAIN, 15));
		}
		return lblNewSalary;
	}
	public JLabel getLblNewAmountOf() {
		if (lblNewAmountOf == null) {
			lblNewAmountOf = new JLabel("New amount of Slots:");
			lblNewAmountOf.setFont(new Font("Tahoma", Font.PLAIN, 15));
		}
		return lblNewAmountOf;
	}
	public JLabel getLblJobIdto() {
		if (lblJobIdto == null) {
			lblJobIdto = new JLabel("Job ID (To update):");
			lblJobIdto.setFont(new Font("Tahoma", Font.PLAIN, 15));
		}
		return lblJobIdto;
	}
	public JTextField getJobID() {
		if (jobID == null) {
			jobID = new JTextField();
			jobID.setColumns(10);
		}
		return jobID;
	}
	public JButton getBtnUpdate() {
		if (btnUpdate == null) {
			btnUpdate = new JButton("Update");
			final Job_UpdateForm panel = this;
			btnUpdate.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {  
					if (CommonControls.validatePanelFields(panel) == true){
					Controller.updateDetails();
					JOptionPane.showMessageDialog(null, "Update Success"); 
					}
				}
			});
			btnUpdate.setFont(new Font("Tahoma", Font.BOLD, 15));
		}
		return btnUpdate;
	}
	public JSpinner getSalarySpinner() {
		if (salarySpinner == null) {
			salarySpinner = new JSpinner();
			salarySpinner.setModel(new SpinnerNumberModel(0, null, 100000, 5));
		}
		return salarySpinner;
	}
	public JSpinner getNoSlots() {
		if (noSlots == null) {
			noSlots = new JSpinner();
			noSlots.setModel(new SpinnerNumberModel(1, 1, 1000, 1));
		}
		return noSlots;
	}
}
